import 'package:flutter/widgets.dart';

import 'gen/app_localizations.dart';

/// 国际化语言调用入口
class S {
  // 国际化语言本地代理类集合
  static const localizationsDelegates = AppLocalizations.localizationsDelegates;

  // 国际化支持的语言
  static const supportedLocales = AppLocalizations.supportedLocales;

  static AppLocalizations? _current;

  /// 多语言实例，使用之前需要调用[load]创建
  static AppLocalizations get current {
    assert(_current != null,
        'No instance of AppLocalizations was loaded. Try to initialize the AppLocalizations before accessing S.current.');
    return _current!;
  }

  /// 初始化全局多语言实例，之后可通过[S.current]调用
  static AppLocalizations load(BuildContext context) {
    _current = of(context);
    return _current!;
  }

  /// 根据上下文创建多语言实例
  static AppLocalizations of(BuildContext context) =>
      AppLocalizations.of(context);
}

/// 英语语言
const String languageEn = "en";

/// 中文语言
const String languageZh = "zh";
